package com.leejie.springboot01;

import java.util.concurrent.CountDownLatch;

/**
 * countDownLatch.countDown(); //数量减一
 * countDownLatch.await(); //等待计数器归零，然后再向下执行
 * 每次有线程调用countDown()数量-1，假设计数器变为0，countDownLatch.await()就会
 * 被唤醒继续执行。
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        Object a = 0;
        for (int i = 1; i <=6 ; i++) {
            Thread th = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+" Go Out...");
                    countDownLatch.countDown();
                }
            },String.valueOf(i));
            th.start();
        }
        countDownLatch.await();
        System.out.println("Close Door");
    }
}
